//
//  RTJBinDetailsCell.m
//  RuiTaiJinProject
//
//  Created by jayson on 2018/12/12.
//  Copyright © 2018年 leewei. All rights reserved.
//

#import "RTJBinDetailsCell.h"
#import "RTJBinCollectionCell.h"

@interface RTJBinDetailsCell ()<UICollectionViewDelegate,UICollectionViewDataSource>

@property (nonatomic,strong)NSMutableArray *arr ;
@end

@implementation RTJBinDetailsCell

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
    
    UICollectionViewFlowLayout *layout = [UICollectionViewFlowLayout new];
    layout.scrollDirection = UICollectionViewScrollDirectionHorizontal;
    //     layout.itemSize = CGSizeMake(215,225);
    //    layout.minimumLineSpacing = 1;//设置最小行间距
    layout.minimumInteritemSpacing = 2;//item间距(最小值)
    layout.sectionInset = UIEdgeInsetsMake(0, 15, 0, 15);//设置section的编距
    
    self.collectionView.collectionViewLayout=layout;
    self.collectionView.delegate = self;
    self.collectionView.dataSource = self;
    self.collectionView.scrollEnabled = YES;
    self.collectionView.showsHorizontalScrollIndicator = NO;
    self.collectionView.backgroundColor = [UIColor whiteColor];
    self.backgroundView=[[UIView alloc] initWithFrame:CGRectZero];
    self.backgroundView.backgroundColor = [UIColor whiteColor];
}

-(void)setData:(NSDictionary *)data{
    
    
    
    _data = data;
    _chujie.text = [NSString stringWithFormat:@"%@",data[@"deal_info"][@"user"][@"real_name"]];
    _shenfen.text = [NSString stringWithFormat:@"%@",data[@"deal_info"][@"user"][@"idno"]];
    _jiekuan.text = [NSString stringWithFormat:@"%@ 元",data[@"deal_info"][@"borrow_amount_thousand_format"]];
    _yongtu.text = [NSString stringWithFormat:@"%@",data[@"deal_info"][@"type_match_row"]];
    _qixian.text = [NSString stringWithFormat:@"%@ 个月",data[@"deal_info"][@"repay_time"]];
    _haikuan.text = [NSString stringWithFormat:@"%@",data[@"deal_info"][@"loantype_format"]];
    _content.text = [NSString stringWithFormat:@"%@",data[@"deal_info"][@"description"]];
    
    [self.collectionView reloadData];
    
    _arr = [NSMutableArray array];
    
    NSArray *arr1 = _data[@"deal_info"][@"img_list"];
    
    for (NSDictionary *dic in arr1) {
        
        NSString *url = dic[@"img"];
        url = [url substringFromIndex:1];
        url=[NSString stringWithFormat:@"%@%@",IMGURL,url];
        
        [_arr addObject:url];
    }
    
}

#pragma makr -UICollectionViewDataSource
- (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView{
    return 1;
}

- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section{
    
    return [_data[@"deal_info"][@"img_list"] count];
    
}

- (__kindof UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{
    //在这里注册自定义的XIBcell否则会提示找不到标示符指定的cell
    UINib *nib = [UINib nibWithNibName:@"RTJBinCollectionCell"bundle: [NSBundle mainBundle]];
    
    [collectionView registerNib:nib forCellWithReuseIdentifier:@"RTJBinCollectionCell"];
    
    RTJBinCollectionCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"RTJBinCollectionCell" forIndexPath:indexPath];
    
    NSArray *arr = _data[@"deal_info"][@"img_list"];
    
    NSString *str = arr[indexPath.row][@"img"];
    
    str = [str substringFromIndex:1];
    [cell.img sd_setImageWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"%@%@",IMGURL,str]] placeholderImage:[UIImage imageNamed:@"kbylogo"]];
    cell.describe.text = [NSString stringWithFormat:@"%@",arr[indexPath.row][@"name"]];
    
    return cell;
    
}

- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath{
    
    if (_delegate &&[_delegate respondsToSelector:@selector(didImagesViewAction:index:)]) {
        
        [_delegate didImagesViewAction:_arr index:indexPath];
    }
    
}

#pragma mark - UICollectionViewDelegateFlowLayout
// 设置格子的大小
- (CGSize) collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout
   sizeForItemAtIndexPath:(NSIndexPath *)indexPath
{
    
    return CGSizeMake(125,160);
    
}


// 设置两行之间cell间距
- (CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout minimumLineSpacingForSectionAtIndex:(NSInteger)section{
    
    return 10;
}



// 设置同行之间cell间距
- (CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout minimumInteritemSpacingForSectionAtIndex:(NSInteger)section{
    
    return 10;
    
}



- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
